<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec"	uri="http://www.springframework.org/security/tags"%>

<s:action name="list" namespace="/users" />
<s:action name="listDisabled" namespace="/users" />
<s:action name="list" namespace="/roles" />
<s:action name="list" namespace="/groups" />

<article>	
	<h1><s:text name="usMan.title"/></h1>
	
	<s:if test="hasActionMessages()">
		<s:actionmessage />
	</s:if>
	<s:if test="hasActionErrors()">
		<s:actionerror />
	</s:if>
	
	<br/><br/>
	<h2><s:text name="usMan.activeUsers"/></h2>
	
	<s:iterator value="%{#request.usersList}" var="currentUser">
		<h3>
			<s:text name="general.username"/>: <s:property value="username"/>
			<a href="javascript:collapseDiv('userDiv_<s:property value="users_id" />')"><s:text name="general.more" /></a>
		</h3>
		
		<div class="displayNone" id="userDiv_<s:property value="users_id" />">
			<b><s:text name="general.roles"/></b>
			<ul><s:iterator value="rolesList" status="rstat">
				<li><s:text name="general.role"/>_<s:property value="%{#rstat.count}"/>: <s:property value="roleName"/></li>
			</s:iterator></ul>
			
			<b><s:text name="general.groups"/></b>
			<ul><s:iterator value="groupsList" status="gstat">
				<li><s:text name="general.group"/>_<s:property value="%{#gstat.count}"/>: <s:property value="groupName"/></li>
			</s:iterator></ul>
			
			<b><s:text name="general.details"/></b>
			<ul>
				<s:if test="%{usrDetails!=null}">
					<li><s:text name="details.name"/>: <s:property value="usrDetails.name"/></li>
					<li><s:text name="details.surname"/>: <s:property value="usrDetails.surname"/></li>
					<li><s:text name="details.email"/>: <s:property value="usrDetails.email"/></li>
					<li><s:text name="details.birthdate"/>: <s:property value="usrDetails.birthdate"/></li>
					<li><s:text name="details.city"/>: <s:property value="usrDetails.city"/></li>
					<li><s:text name="details.address"/>: <s:property value="usrDetails.address"/></li>
					<li><s:text name="details.phoneNumber"/>: <s:property value="usrDetails.phoneNumber"/></li>
					<li><s:text name="details.cellNumber"/>: <s:property value="usrDetails.cellNumber"/></li>
					<li><s:text name="details.taxCode"/>: <s:property value="usrDetails.taxCode"/></li>
				</s:if>
			</ul>
			
			<b><s:text name="usMan.editUser"/></b>
			<s:form action="edit" namespace="/users" method="post">
				<s:textfield name="userEdit.username" value="%{username}" key="general.username" />
				<s:textfield name="userEdit.password" value="%{password}" key="general.password" />
				<ul>
					<li><s:text name="general.roles"/>: &nbsp;&nbsp;<s:checkboxlist list="%{#request.rolesList.{roleName}}" value="rolesList.{roleName}" name="rstrings" theme="simple"/></li>
				</ul>
				<ul>
					<li><s:text name="general.groups"/>: <s:checkboxlist list="%{#request.groupsList.{groupName}}" value="groupsList.{groupName}" name="gstrings" theme="simple"/></li>
				</ul>
				<s:hidden name="page" value="%{page}" />
				<s:hidden name="username" value="%{username}" />
				<s:submit method="edit" key="general.edit" onclick="return confirm('Confirm?')" />
			</s:form>
			
			<s:url action="deleteLogical" namespace="/users" var="del">
				<s:param name="username" value="username" />
				<s:param name="page" value="%{page}" />
			</s:url>
			<span class="padleft"><s:a href="%{del}" onclick="return confirm('Confirm?')"><s:text name="usMan.deleteUser"/></s:a><br /></span>
			
			<br/>
			<b><s:text name="usMan.editUsrDetails"/></b>
			<s:form action="merge" namespace="/usrdetails" method="post">
				<s:textfield name="usrDetailsIns.name" key="details.name" value="%{usrDetails.name}"/>
				<s:textfield name="usrDetailsIns.surname" key="details.surname" value="%{usrDetails.surname}"/>
				<s:textfield name="usrDetailsIns.email" key="details.email" value="%{usrDetails.email}"/>
				<s:textfield name="usrDetailsIns.birthdate" key="details.birthdate" value="%{usrDetails.birthdate}" placeholder="%{getText('general.date.placeholder')}"/>
				<s:textfield name="usrDetailsIns.city" key="details.city" value="%{usrDetails.city}"/>
				<s:textfield name="usrDetailsIns.address" key="details.address" value="%{usrDetails.address}"/>
				<s:textfield name="usrDetailsIns.phoneNumber" key="details.phoneNumber" value="%{usrDetails.phoneNumber}"/>
				<s:textfield name="usrDetailsIns.cellNumber" key="details.cellNumber" value="%{usrDetails.cellNumber}"/>
				<s:textfield name="usrDetailsIns.taxCode" key="details.taxCode" value="%{usrDetails.taxCode}"/>
				<s:hidden name="page" value="%{page}" />
				<s:hidden name="username" value="%{username}"/>
				<s:submit method="merge" key="general.edit" onclick="return confirm('Confirm?')" />
			</s:form>
			
			<s:url action="delete" namespace="/usrdetails" var="delUsrDet">
				<s:param name="usrDetails_id" value="%{usrDetails.usrDetails_id}"/>
				<s:param name="username" value="%{username}"/>
				<s:param name="page" value="%{page}"/>
			</s:url>
			<s:if test="%{usrDetails!=null}">
				<span class="padleft"><s:a href="%{delUsrDet}" onclick="return confirm('Confirm?')"><s:text name="details.delete"/></s:a><br /></span>
			</s:if>
		</div>
	</s:iterator>

	<br/><br/>
	<h2><s:text name="usMan.disUsers"/></h2>
	<s:iterator value="%{#request.usersListDisabled}" var="currentUserDisabled">
		<h3>
			<s:text name="general.username"/>: <s:property value="username"/>
			<a href="javascript:collapseDiv('userDisDiv_<s:property value="users_id" />')"><s:text name="general.more" /></a>
		</h3>
		
		<div class="displayNone" id="userDisDiv_<s:property value="users_id" />">
			<b><s:text name="general.roles"/></b>
			<ul><s:iterator value="rolesList" status="rstat">
				<li><s:text name="general.role"/>_<s:property value="%{#rstat.count}"/>: <s:property value="roleName"/></li>
			</s:iterator></ul>
			
			<b><s:text name="general.groups"/></b>
			<ul><s:iterator value="groupsList" status="gstat">
				<li><s:text name="general.group"/>_<s:property value="%{#gstat.count}"/>: <s:property value="groupName"/></li>
			</s:iterator></ul>
			
			<b><s:text name="general.details"/></b>
			<ul>
				<s:if test="%{usrDetails!=null}">
					<li><s:text name="details.name"/>: <s:property value="usrDetails.name"/></li>
					<li><s:text name="details.surname"/>: <s:property value="usrDetails.surname"/></li>
					<li><s:text name="details.email"/>: <s:property value="usrDetails.email"/></li>
					<li><s:text name="details.birthdate"/>: <s:property value="usrDetails.birthdate"/></li>
					<li><s:text name="details.city"/>: <s:property value="usrDetails.city"/></li>
					<li><s:text name="details.address"/>: <s:property value="usrDetails.address"/></li>
					<li><s:text name="details.phoneNumber"/>: <s:property value="usrDetails.phoneNumber"/></li>
					<li><s:text name="details.cellNumber"/>: <s:property value="usrDetails.cellNumber"/></li>
					<li><s:text name="details.taxCode"/>: <s:property value="usrDetails.taxCode"/></li>
				</s:if>
			</ul>
			
			<s:url action="restore" namespace="/users" var="rest">
				<s:param name="username" value="username" />
				<s:param name="page" value="%{page}" />
			</s:url>
			<span class="padleft"><s:a href="%{rest}" onclick="return confirm('Confirm?')"><s:text name="general.restore"/></s:a></span>
			<br/>
		
			<s:url action="deletePhisical" namespace="/users" var="delPhis">
				<s:param name="username" value="username" />
				<s:param name="page" value="%{page}" />
			</s:url>
			<span class="padleft"><s:a href="%{delPhis}" onclick="return confirm('Confirm?')"><s:text name="general.delete.perm"/></s:a></span>
		</div>
	</s:iterator>

	
	<br/>
	<h3><s:text name="usMan.insUser"/></h3>
	<s:form action="insert" namespace="/users" method="post">
		<s:textfield name="userIns.username" key="general.username" value=""/>
		<s:password name="userIns.password" key="general.password" value=""/>
		<s:checkboxlist list="%{#request.rolesList.{roleName}}" value="" name="rstrings" key="general.roles"/>
		<s:checkboxlist list="%{#request.groupsList.{groupName}}" value="" name="gstrings" key="general.groups"/>
		<s:hidden name="page" value="%{page}" />
		<s:submit method="insert" key="general.insert" onclick="return confirm('Confirm?')" />
	</s:form>
</article>